package com.ithong.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ithong.drug.entity.Problem;
import com.ithong.drug.mapper.ProblemMapper;
import com.ithong.drug.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

import java.util.List;

@Service
public class ProblemServiceImpl extends ServiceImpl<ProblemMapper, Problem> implements ProblemService {

    @Autowired
    private ProblemMapper problemMapper;

    @Override
    public IPage<Problem> selectproblemPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Problem> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(param)){
            wrapper.like("dname",param);
        }
        Page<Problem> page = new Page<>(pageNum,pageSize);
        return problemMapper.selectPage(page,wrapper);
    }

    @Override
    public int addproblem(Problem problem) {
        return problemMapper.insert(problem);
    }

    @Override
    public int editproblem(Problem problem) {
        return problemMapper.updateById(problem);
    }

    @Override
    public Problem queryproblemById(Integer id) {
        return problemMapper.selectById(id);
    }

    @Override
    public int delproblem(Integer id) {
        return problemMapper.deleteById(id);
    }

    @Override
    public List<Problem> queryproblemList() {
        return problemMapper.selectList(null);
    }
}
